package com.huawei.appgallery.forum.cards.card;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.TextView;
import com.huawei.appgallery.forum.base.card.ForumCard;
import com.huawei.appgallery.forum.base.card.bean.SortInfo;
import com.huawei.appgallery.forum.cards.bean.ForumTitleSortCardBean;
import com.huawei.appgallery.forum.cards.widget.SortSpinner;
import com.huawei.appgallery.forum.cards.widget.SortSpinner.e;
import com.huawei.appgallery.forum.cards.widget.SpinnerAdapter;
import com.huawei.appgallery.foundation.ui.framework.cardkit.bean.CardBean;
import java.util.ArrayList;
import java.util.List;
import o.azb;
import o.bsy.c;
import o.bsy.d;
import o.bsy.h;
import o.bsy.j;
import o.buj;
import o.buk;
import o.cgz;
import o.CollectCheck;
import o.ll;

public class ForumTitleSortCard extends ForumCard implements e {
    private View ʻ;
    private boolean ʼ;
    private buj ʽ = null;
    private TextView ˊ;
    private Context ˋ;
    private boolean ˎ = false;
    protected buk ˏ = null;
    private int ˏॱ = -1;
    private TextView ॱ;
    private SpinnerAdapter ॱˊ;
    private View ॱॱ;
    private SortSpinner ᐝ;

    public void ˎ(boolean z) {
        this.ˎ = z;
    }

    public void ˎ() {
        this.ʼ = true;
    }

    public ForumTitleSortCard(Context context) {
        super(context);
        this.ˋ = context;
        if (this.ˋ instanceof buk) {
            this.ˏ = (buk) this.ˋ;
        }
        if (this.ˋ instanceof buj) {
            this.ʽ = (buj) this.ˋ;
        }
    }

    public cgz ˏ(View view) {
        ʽ(view);
        this.ॱॱ = view.findViewById(c.ॱˑ);
        this.ʻ = view.findViewById(c.ॱـ);
        if (this.ʼॱ instanceof Activity) {
            azb.ˏ(view, c.ॱﾞ);
        }
        this.ॱ = (TextView) view.findViewById(c.ॱᐨ);
        this.ˊ = (TextView) view.findViewById(c.ॱㆍ);
        this.ᐝ = (SortSpinner) view.findViewById(c.ॱꜞ);
        this.ˊ.setOnClickListener(new OnClickListener(this) {
            final /* synthetic */ ForumTitleSortCard ˏ;

            {
                this.ˏ = r1;
            }

            public void onClick(View view) {
                this.ˏ.ᐝ();
            }
        });
        return this;
    }

    public void ˏ(CardBean cardBean) {
        super.ˏ(cardBean);
        if (cardBean instanceof ForumTitleSortCardBean) {
            ForumTitleSortCardBean forumTitleSortCardBean = (ForumTitleSortCardBean) cardBean;
            if (this.ʽ != null) {
                int P_ = this.ʽ.P_();
                buj o_buj = this.ʽ;
                if (P_ == 2 && this.ʽ.ॱॱ() == 1) {
                    this.ॱॱ.setVisibility(0);
                    this.ʻ.setVisibility(8);
                    if (CollectCheck.isEmpty(forumTitleSortCardBean.ʻ())) {
                        this.ᐝ.setVisibility(0);
                        ॱ(forumTitleSortCardBean);
                    } else {
                        this.ᐝ.setVisibility(8);
                    }
                    if (this.ʽ != null) {
                        this.ॱ.setText(forumTitleSortCardBean.ᐝ());
                    }
                    this.ॱ.setText(this.ˋ.getResources().getString(j.ˎ, new Object[]{Integer.valueOf(forumTitleSortCardBean.ˊ())}));
                    this.ˊ.setText(this.ˋ.getResources().getQuantityString(h.ˏ, forumTitleSortCardBean.ˊ(), new Object[]{Integer.valueOf(forumTitleSortCardBean.ˊ())}));
                    return;
                }
            }
            this.ॱॱ.setVisibility(8);
            this.ʻ.setVisibility(0);
            if (CollectCheck.isEmpty(forumTitleSortCardBean.ʻ())) {
                this.ᐝ.setVisibility(0);
                ॱ(forumTitleSortCardBean);
            } else {
                this.ᐝ.setVisibility(8);
            }
            if (this.ʽ != null) {
                this.ॱ.setText(this.ˋ.getResources().getString(j.ˎ, new Object[]{Integer.valueOf(forumTitleSortCardBean.ˊ())}));
                this.ˊ.setText(this.ˋ.getResources().getQuantityString(h.ˏ, forumTitleSortCardBean.ˊ(), new Object[]{Integer.valueOf(forumTitleSortCardBean.ˊ())}));
                return;
            }
            this.ॱ.setText(forumTitleSortCardBean.ᐝ());
        }
    }

    private int ˏ(ForumTitleSortCardBean forumTitleSortCardBean) {
        int i = 0;
        for (SortInfo sortInfo : forumTitleSortCardBean.ʻ()) {
            int i2;
            if ("desc".equals(sortInfo.ˊ()) && sortInfo.ˎ()) {
                i2 = 1;
            } else if ("asc".equals(sortInfo.ˊ()) && sortInfo.ˎ()) {
                i2 = 0;
            } else {
                i2 = i;
            }
            i = i2;
        }
        return i;
    }

    private void ॱ(ForumTitleSortCardBean forumTitleSortCardBean) {
        int i = 1;
        String string = this.ˋ.getResources().getString(j.ʾ);
        String string2 = this.ˋ.getResources().getString(j.ˈ);
        int ˏ = ˏ(forumTitleSortCardBean);
        List arrayList = new ArrayList();
        arrayList.add(string2);
        arrayList.add(string);
        if (this.ˏ != null) {
            int ˎ = this.ˏ.ˎ();
            if (ˎ == 1) {
                i = 0;
            } else if (ˎ != 0) {
                i = ˏ;
            }
        } else {
            i = ˏ;
        }
        if (this.ˏॱ != i) {
            ˋ(arrayList, i);
        }
    }

    private void ˋ(List<String> list, int i) {
        this.ˏॱ = i;
        if (this.ॱˊ == null) {
            this.ॱˊ = new SpinnerAdapter(this.ˋ, list);
            if (this.ˎ) {
                this.ॱˊ.setImmer(true);
                this.ॱˊ.setTextColor(this.ˋ.getResources().getColor(d.ᐝ));
                this.ॱˊ.setFromBuoy(true);
            }
            this.ᐝ.setAdapter(this.ॱˊ);
        }
        this.ʼ = false;
        this.ᐝ.setOnItemSelectedListener(new OnItemSelectedListener(this) {
            final /* synthetic */ ForumTitleSortCard ˋ;

            {
                this.ˋ = r1;
            }

            public void onItemSelected(AdapterView<?> adapterView, View view, int i, long j) {
                if (!this.ˋ.ʼ || this.ˋ.ˏॱ == i) {
                    return;
                }
                if (i == 0) {
                    this.ˋ.ˋ(1);
                    if (this.ˋ.ˏ != null) {
                        this.ˋ.ˏ.ˏ(1);
                        return;
                    }
                    return;
                }
                this.ˋ.ˋ(0);
                if (this.ˋ.ˏ != null) {
                    this.ˋ.ˏ.ˏ(0);
                }
            }

            public void onNothingSelected(AdapterView<?> adapterView) {
            }
        });
        this.ᐝ.setSelection(this.ˏॱ);
        this.ᐝ.setExtendClick(this);
    }

    private void ˋ(int i) {
        Intent intent = new Intent("forum.comments.list.refresh");
        intent.putExtra("notify_type", i);
        ll.ˏ(this.ˋ).ˋ(intent);
    }

    private void ᐝ() {
        ll.ˏ(this.ˋ).ˋ(new Intent("forum.comments.list.refresh.all"));
    }
}
